package com.ruoyi.web.controller.farmer;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.farmer.domain.Warehousesku;
import com.ruoyi.farmer.service.IWarehouseskuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库库存Controller
 *
 * @author 姚毫征
 * @date 2023-09-12
 */
@RestController
@RequestMapping("/warehousesku/warehousesku")
public class WarehouseskuController extends BaseController
{
    @Autowired
    private IWarehouseskuService warehouseskuService;

    /**
     * 查询仓库库存列表
     */
    @PreAuthorize("@ss.hasPermi('warehousesku:warehousesku:list')")
    @GetMapping("/list")
    public TableDataInfo list(Warehousesku warehousesku)
    {
        startPage();
        List<Warehousesku> list = warehouseskuService.selectWarehouseskuList(warehousesku);
        return getDataTable(list);
    }

    /**
     * 导出仓库库存列表
     */
    @PreAuthorize("@ss.hasPermi('warehousesku:warehousesku:export')")
    @Log(title = "仓库库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Warehousesku warehousesku)
    {
        List<Warehousesku> list = warehouseskuService.selectWarehouseskuList(warehousesku);
        ExcelUtil<Warehousesku> util = new ExcelUtil<Warehousesku>(Warehousesku.class);
        util.exportExcel(response, list, "仓库库存数据");
    }

    /**
     * 获取仓库库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehousesku:warehousesku:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(warehouseskuService.selectWarehouseskuById(id));
    }

    /**
     * 新增仓库库存
     */
    @PreAuthorize("@ss.hasPermi('warehousesku:warehousesku:add')")
    @Log(title = "仓库库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Warehousesku warehousesku)
    {

        warehousesku.setCreateTime(DateUtils.getTime());
        return toAjax(warehouseskuService.insertWarehousesku(warehousesku));
    }

    /**
     * 修改仓库库存
     */
    @PreAuthorize("@ss.hasPermi('warehousesku:warehousesku:edit')")
    @Log(title = "仓库库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Warehousesku warehousesku)
    {
        warehousesku.setUpdateTime(DateUtils.getTime());
        return toAjax(warehouseskuService.updateWarehousesku(warehousesku));
    }

    /**
     * 删除仓库库存
     */
    @PreAuthorize("@ss.hasPermi('warehousesku:warehousesku:remove')")
    @Log(title = "仓库库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(warehouseskuService.deleteWarehouseskuByIds(ids));
    }
}
